
package com.kanjian.music.adapter;

import java.util.ArrayList;

import com.kanjian.music.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LiveChatListAdapter extends BaseAdapter {

    private ArrayList<String> mData = new ArrayList<String>();

    private LayoutInflater mLayoutInflater;

    public LiveChatListAdapter(Context context) {
        mLayoutInflater = LayoutInflater.from(context);
    }
    
    public void addMessage (String msg) {
        mData.add(msg);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData != null ? mData.size() : 0;
    }

    @Override
    public String getItem(int position) {
        return mData != null ? mData.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            convertView = mLayoutInflater.inflate(R.layout.item_list_recommend_title, null);
            holder = new ViewHolder();
            holder.mTv_msg = (TextView) convertView.findViewById(R.id.item_list_recommend_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mTv_msg.setText(getItem(position));
        return convertView;
    }

    static class ViewHolder {
        TextView mTv_msg;
    }

}
